﻿using System;
using System.Collections.ObjectModel;

namespace Mono.Cecil {

	public sealed class ParameterDefinitionCollection : Collection<ParameterDefinition> {

		protected override void InsertItem (int index, ParameterDefinition item)
		{
			base.InsertItem (index, item);

			if (index != Count - 1)
				ComputeIndexes ();
		}

		protected override void SetItem (int index, ParameterDefinition item)
		{
			base.SetItem (index, item);

			item.Index = index;
		}

		protected override void RemoveItem (int index)
		{
			base.RemoveItem (index);

			if (index != Count - 1)
				ComputeIndexes ();
		}

		void ComputeIndexes ()
		{
			for (int i = 0; i < this.Count; i++)
				this [i].Index = i;
		}
	}
}
